helper/schema: Default hashing function for sets #3018
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A common issue with new resource implementations is not considering parts of a complex structure that's used inside a set, which causes quirky behavior.
The schema helper has enough information to provide a default reasonable implementation of a set function that includes all non-computed attributes in a deterministic way. Here we implement such a function and use it when no explicit hashing function is provided.
In order to achieve this we encapsulate the construction of the zero value for a schema in a new method
schema.ZeroValue
, which allows us to put the fallback logic to the new default function in a single spot. It is no longer valid to use&Set{F: schema.Set}
and all uses of that construct should be replaced withschema.ZeroValue().(*Set)
.This was originally discussed in the feedback on #2336.